<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Builtin Modules and Custom Interpreters &mdash; SIP 4.10.2 Reference Guide</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '4.10.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="SIP 4.10.2 Reference Guide" href="index.html" />
    <link rel="prev" title="Building Your Extension with distutils" href="distutils.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="distutils.html" title="Building Your Extension with distutils"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">SIP 4.10.2 Reference Guide</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="builtin-modules-and-custom-interpreters">
<span id="ref-builtin"></span><h1>Builtin Modules and Custom Interpreters<a class="headerlink" href="#builtin-modules-and-custom-interpreters" title="Permalink to this headline">¶</a></h1>
<p>Sometimes you want to create a custom Python interpreter with some modules
built in to the interpreter itself rather than being dynamically loaded.  To
do this the module must be created as a static library and linked with a
custom stub and the normal Python library.</p>
<p>To build the SIP module as a static library you must pass the <tt class="docutils literal"><span class="pre">-k</span></tt> command
line option to <tt class="docutils literal"><span class="pre">configure.py</span></tt>.  You should then build and install SIP as
normal.  (Note that, because the module is now a static library, you will not
be able to import it.)</p>
<p>To build a module you have created for your own library you must modify your
own configuration script to pass a non-zero value as the <tt class="docutils literal"><span class="pre">static</span></tt> argument
of the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the <a title="sipconfig.ModuleMakefile" class="reference external" href="build_system.html#sipconfig.ModuleMakefile"><tt class="xref docutils literal"><span class="pre">sipconfig.ModuleMakefile</span></tt></a> class (or
any derived class you have created).  Normally you would make this configurable
using a command line option in the same way that SIP&#8217;s <tt class="docutils literal"><span class="pre">configure.py</span></tt> handles
it.</p>
<p>The next stage is to create a custom stub and a Makefile.  The SIP distribution
contains a directory called <tt class="docutils literal"><span class="pre">custom</span></tt> which contains example stubs and a
Python script that will create a correct Makefile.  Note that, if your copy of
SIP was part of a standard Linux distribution, the <tt class="docutils literal"><span class="pre">custom</span></tt> directory may
not be installed on your system.</p>
<p>The <tt class="docutils literal"><span class="pre">custom</span></tt> directory contains the following files.  They are provided as
examples - each needs to be modified according to your particular
requirements.</p>
<blockquote>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">mkcustom.py</span></tt> is a Python script that will create a Makefile which is
then used to build the custom interpreter.  Comments in the file describe
how it should be modified.</li>
<li><tt class="docutils literal"><span class="pre">custom.c</span></tt> is a stub for a custom interpreter on Linux/UNIX.  It
should also be used for a custom console interpreter on Windows (i.e.
like <tt class="docutils literal"><span class="pre">python.exe</span></tt>).  Comments in the file describe how it should be
modified.</li>
<li><tt class="docutils literal"><span class="pre">customw.c</span></tt> is a stub for a custom GUI interpreter on Windows (i.e.
like <tt class="docutils literal"><span class="pre">pythonw.exe</span></tt>).  Comments in the file describe how it should be
modified.</li>
</ul>
</blockquote>
<p>Note that this technique does not restrict how the interpreter can be used.
For example, it still allows users to write their own applications that can
import your builtin modules.  If you want to prevent users from doing that,
perhaps to protect a proprietary API, then take a look at the
<a class="reference external" href="http://www.riverbankcomputing.com/software/vendorid/">VendorID</a> package.</p>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h4>Previous topic</h4>
            <p class="topless"><a href="distutils.html"
                                  title="previous chapter">Building Your Extension with distutils</a></p>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="distutils.html" title="Building Your Extension with distutils"
             >previous</a> |</li>
        <li><a href="index.html">SIP 4.10.2 Reference Guide</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010 Riverbank Computing Limited.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
    </div>
  </body>
</html>